<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogVisible"
    width="80%"
    custom-class="scrollable-dialog"
    :close-on-click-modal="false"
  >
    <supplier-common-list
      ref="createSupplier"
      :tableData="tables.tableData"
      :tableLabel="tables.tableLabel"
      @on-detail-click="supplierDetailClick"
      @on-store-detail-click="storeDetailClick"
      @on-search-click="loadList"
      :models="tables"
    />

    <div slot="footer" class="dialog-footer">
      <el-button size="small" @click="dialogVisible = false">取 消</el-button>
    </div>

    <supplierDetail ref="createSupplierDetail" />
    <storeInfo ref="createStoreInfo" />
  </el-dialog>
</template>
<script>
import moment from "moment";
import { mapGetters, mapActions } from "vuex";
import supplierCommonList from "@/views/supplier/supplierModel/supplier_common_list.vue";
import supplierDetail from "@/views/supplier/supplierModel/supplier_detail.vue";
import storeInfo from "@/views/supplier/supplierModel/info_store.vue";
import * as CommonConfig from "@/views/supplier/supplierModel/config";
import * as CommonApi from "@/api/supplier_api";
export default {
  components: {
    supplierCommonList,
    supplierDetail,
    storeInfo
  },
  data() {
    return {
      dialogVisible: false,
      title: "",
      paramType: "",
      listType: "",
      tables: {
        total: 0,
        isStore: true,
        tableData: [],
        tableLabel: []
      },
      models: {
        pageNum: 1,
        pageSize: 10
      }
    };
  },
  computed: {
    ...mapGetters(["findType"])
  },
  filters: {
    filterTime(val) {
      if (!val) {
        return;
      }
      return moment(val).format("YYYY-MM-DD  HH:mm:ss");
    }
  },
  methods: {
    loadList(formData) {
       if (this.listType == "reg") {
        this.loadRegList(formData);
      } else if (this.listType == "store") {
        this.loadStoreList(formData);
      } else if (this.listType == 'pause') {
        this.loadPauseMonthList(formData);
      } else if (this.listType == 'black') {
        this.loadBlackList(formData);
      } else if (this.listType == 'notice') {
        this.loadNotice(formData);
      }
    },
    openTable(title, paramType, listType) {
      this.title = title;
      this.paramType = paramType;
      this.listType = listType;
      if (listType == "reg") {
        this.tables.tableLabel = CommonConfig.SUPPLIER_LABEL;
        this.loadRegList(true);
      } else if (listType == "store") {
        this.tables.tableLabel = CommonConfig.SUPPLIER_STORE_LABEL;
        this.loadStoreList(true);
      } else if (listType == 'pause') {
        this.tables.tableLabel = CommonConfig.SUPPLIER_PAUSE_LABEL;
        this.loadPauseMonthList(true);
      } else if (listType == 'black') {
        this.tables.tableLabel = CommonConfig.SUPPLIER_BLACKLIST_LABEL;
        this.loadBlackList(true);
      } else if (listType == 'notice') {
        this.tables.tableLabel = CommonConfig.NOTICE_LABEL;
        this.loadNotice(true);
      }
      this.dialogVisible = true;
    },
    //通知
     async loadNotice(formData) {
       let param = {};
          if (typeof formData == 'boolean') {
        this.models.pageNum = 1;
        this.models.pageSize = 10;
      }
      if (typeof formData == 'object') {
         this.models.pageNum = formData.pageNum;
        this.models.pageSize = formData.pageSize;
      }
       param.pageNum = this.models.pageNum
        param.pageSize = this.models.pageSize;
       const { code, data } = await CommonApi.getNoticePage(param);
       this.tables.total = data.total;
        this.tables.tableData = data.list;
    },
    //黑名单
    async loadBlackList(formData) {
      let param = {}
           if (typeof formData == 'boolean') {
        this.models.pageNum = 1;
        this.models.pageSize = 10;
      }
      if (typeof formData == 'object') {
         this.models.pageNum = formData.pageNum;
        this.models.pageSize = formData.pageSize;
      }
       param.pageNum = this.models.pageNum
        param.pageSize = this.models.pageSize;
       param.tag = "3"
      const { code, data } = await CommonApi.supplierPageFind(param);
       data.list.forEach(v => {
          v.supplierId = v.id
        });
        this.tables.total = data.total;
        this.tables.tableData = data.list;
    },
       //暂停 3月
    async loadPauseMonthList(formData) {
      let param = {}
         if (typeof formData == 'boolean') {
        this.models.pageNum = 1;
        this.models.pageSize = 10;
      }
      if (typeof formData == 'object') {
         this.models.pageNum = formData.pageNum;
        this.models.pageSize = formData.pageSize;
      }
      param.pageNum = this.models.pageNum
      param.pageSize = this.models.pageSize;
      param.pauseCycle = this.paramType;
      param.isPaused =1
      const { data } = await CommonApi.getSupplierStorePage(param);
      data.list.forEach(v => {
        v.supplierId = v.id;
      });
      this.tables.total = data.total;
      this.tables.tableData = data.list;
    },
    
    loadStoreList(formData) {
      let param = {};
       if (typeof formData == 'boolean') {
        this.models.pageNum = 1;
        this.models.pageSize = 10;
      }
      if (typeof formData == 'object') {
         this.models.pageNum = formData.pageNum;
        this.models.pageSize = formData.pageSize;
      }
      param.pageNum = this.models.pageNum
      param.pageSize = this.models.pageSize;
      param.storeStatus = this.paramType;
      param.storeType = "1";
      CommonApi.getSupplierStorePage(param).then(async res => {
        const { code, data } = res;
        data.list.forEach(v => {
          v.id = v.applyId;
        });
        this.tables.tableData = data.list;
        this.tables.total = data.total;
        // if (this.paramType == 2) { //如何事驳回的情况 需要过滤待审核的情况
        //   const src = data.list.filter(v=> v.newUpdateId && v.newUpdateStatus)
        //  const result = data.list.filter(v=> !v.newUpdateId && !v.newUpdateStatus)
        //   this.tables.tableData = result;
        //   this.tables.total = data.total - src.length;
        // } else {
        //    this.tables.total = data.total;
        //   data.list.forEach(v => {
        //     if (v.newUpdateId && v.newUpdateStatus && v.storeStatus !== '1') { // 有值的情况下 更改状态 并且不是通过状态
        //       v.storeStatus = "0"
        //     }
        //   });
        //   this.tables.tableData = data.list;
        // }
       
      });
    },
    async loadRegList(formData) {
      let param = {};
       if (typeof formData == 'boolean') {
        this.models.pageNum = 1;
        this.models.pageSize = 10;
      }
      if (typeof formData == 'object') {
         this.models.pageNum = formData.pageNum;
        this.models.pageSize = formData.pageSize;
      }
       param.pageNum = this.models.pageNum
        param.pageSize = this.models.pageSize;
      param.statusFlag = this.paramType;
      param.queryType = this.findType["reg"];
      CommonApi.supplierPageFind(param).then(async res => {
        const { code, data } = res;
        this.tables.total = data.total;
        this.tables.tableData = data.list;
      });
    },
    supplierDetailClick(row) {
      this.$refs.createSupplierDetail.openDetail(row, 1);
    },
    storeDetailClick(row) {
      this.$refs.createStoreInfo.openDetail(row);
    }
  }
};
</script>
<style scoped>
.mo-box {
  margin-bottom: 25px;
}
</style>
